<?php
include_once '../common_mbs.inc.php';
include_once '../smarty.inc.php';

$imgurl = $_REQUEST['imgurl'];
if(!empty($imgurl))
{
	 $path =  'E:/wamp/www/qy/upload/productimg/'.$imgurl;
	 if(empty($_REQUEST['onlyimg'])){
		 if(file_exists($path)){
			 unlink($path);
			 echo 1;
		 }else{
			 echo 0;
		 }
	  }else{
		  $img_obj = new product_img_cls();
		  $data = $img_obj->del_img_by_url($imgurl);
		  if($data){			
			 unlink($path);			
			 echo 1;
		 }else{
			 echo 0;
		 }
	  }
}


if(!empty($_REQUEST['idstr'])){
            $ids = explode(',',$_REQUEST['idstr']);
            $path = $_upload_path;
            array_pop($ids);
            for($i=0;$i<count($ids);$i++){
			  $product_img_obj = new product_img_cls();

              $result =  M("group")->where("group_id = {$ids[$i]}")->delete();
              $imgData = M('product_img')->where("product_id={$ids[$i]}")->select();
              if(!empty($imgData)){
                  for($k=0;$k<count($imgData);$k++){
                      if(file_exists($path.$imgData[$k]['product_img'])){
                          unlink($path.$imgData[$k]['product_img']);
                          unlink($path.'thumbnail_'.$imgData[$k]['product_img']);
                      }
                  }
              }
              M('product_img')->where("product_id={$ids[$i]}")->delete();
            }
            if($result){
                 $this->success('删除成功');
            }
        }
?>